<template>
  <div class="my-template">
    <div>
      <div class="my-l-butt">
        <el-button type="danger" plain @click="delObjs()">删除</el-button>
      </div>

      <div class="my-r-float">
        <el-input placeholder="请输入任务名称" v-model="inputObjName" class="input-with-select">
          <el-button slot="append" icon="el-icon-search" @click="inputFunc()"></el-button>
        </el-input>
      </div>

      <div>
        <!--内容组件-->
        <el-table
          ref="multipleTable"
          :data="tableData"
          class="my-put"
          tooltip-effect="dark"
          @selection-change="handleSelectionChange">

          <el-table-column
            type="selection"
            width="55">
          </el-table-column>

          <el-table-column
            prop="id"
            label="ID"
            width="100">
          </el-table-column>

          <el-table-column
            prop="task_id"
            label="任务id"
            width="320">
          </el-table-column>

          <el-table-column
            prop="date_done"
            label="完成日期"
            width="250">
            <template slot-scope="scope">
              <div class="block">
                <el-date-picker
                  disabled
                  v-model="scope.row.date_done"
                  type="datetime"
                  placeholder="选择日期时间"
                  align="right">
                </el-date-picker>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="task_name"
            label="函数名称"
            width="200">
            <template slot-scope="scope" v-if="scope.row.task_name">
              <el-select disabled v-model="scope.row.task_name" placeholder="请选择执行函数" class="my-put">
                <el-option
                  v-for="(item,index) in optionsExeFunc"
                  :key="index"
                  :label="item.value"
                  :value="item.id"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>

          <el-table-column
            prop="task_args"
            label="位置参数"
            width="200">
            <template slot-scope="scope">
              <div class="mytable" v-text="scope.row.task_args">
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="task_kwargs"
            label="关键字参数"
            width="200">
            <template slot-scope="scope">
              <div class="mytable" v-text="scope.row.task_kwargs">
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="result"
            label="返回值"
            width="300">
            <template slot-scope="scope">
              <div class="mytable" v-text="scope.row.result">
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="content_type"
            label="数据类型"
            width="200">
          </el-table-column>

          <el-table-column
            prop="content_encoding"
            label="数据编码"
            width="200">
          </el-table-column>

          <el-table-column
            prop="traceback"
            label="回溯"
            width="200">
            <template slot-scope="scope">
              <div class="mytable" v-text="scope.row.traceback">
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="hidden"
            label="隐藏"
            width="200">
            <template slot-scope="scope">
              <div class="mytable" v-text="scope.row.hidden">
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="meta"
            label="目标"
            width="200">
            <template slot-scope="scope">
              <div class="mytable" v-text="scope.row.meta">
              </div>
            </template>
          </el-table-column>

          <el-table-column
            fixed="right"
            prop="status"
            label="执行结果"
            width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.status==='SUCCESS'" class="my-succes">{{ scope.row.status }}</div>
              <div v-else-if="scope.row.status==='FAILURE'" class="my-failure">{{ scope.row.status }}</div>
              <div v-else class="my-no-in">{{ scope.row.status }}</div>
            </template>
          </el-table-column>

          <el-table-column
            fixed="right"
            label="操作"
            width="100">
            <template slot-scope="scope">
              <!--<router-link :to="{name: EditName, query: { task_result_id: scope.row.id }}">-->
              <!--<el-button type="text" size="small">编辑</el-button>-->
              <!--</router-link>-->
              <el-button type="text" size="small" @click="delObjs(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页组件-->
      <div class="block paging">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          prev-text="上一页"
          next-text="下一页"
          layout="total, sizes, prev, pager, next, jumper"
          :total="dataCount">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'TaskResult',
    data() {
      return {
        // 需要搜索的项目名称
        inputObjName: '',  // 搜索功能实现的字符串
        // choices设置
        optionsTimezone: [],
        optionsExeFunc: [],  // 执行函数

        EditName: 'EditTaskResult',

        // 分页设置
        currentPage: 1, //当前页码
        pageSize: 10,    //    每页的条数
        pageSizes: [10, 20, 50, 100, 200, 500, 1000],  // 可选每页显示条数
        dataCount: 0,  // 数据总条数

        // 数据设置
        ListDataURL: this.$http.TaskResultURL,  // 表格列表数据获取
        objID: 'task_result_id',
        tableData: [],  // 阿贾克斯获取的初始数据
        multipleSelection: [],  // 不能删，我也不知道是干嘛用的，删了会报错

      }
    },
    created() {
      // 发送啊假克丝请求
      this.objList();// 阿贾克斯获取的初始数据
      this.optionsTimezone = this.getChoices.task.timezone;
      this.optionsExeFunc = this.getChoices.task.exe_func;
    },

    methods: {
      handleClick(row) {
        console.log(row);
      },
      // 修改每页显示条数
      handleSizeChange(val) {
        this.pageSize = val;  // 修改每页显示条数
        this.currentPage = 1;  // 修改页码
      },
      // 修改页码
      handleCurrentChange(val) {
        this.currentPage = val;  // 修改页码
      },

      // 发送啊假克丝请求 得到表格的原始数据
      objList() {
        this.$myTool.objList(this)
      },
      // 删除函数，调用了删除接口
      delObjs(objId) {
        this.$myTool.delObjs(objId, this)
      },
      // 不能删
      handleSelectionChange(val) {
        this.multipleSelection = val;
        console.log(this.multipleSelection)
      },
      //  按项目名称搜索的函数
      inputFunc() {
        let queryData = {
          'page': this.currentPage,
          'size': this.pageSize,
          'inputObjName': this.inputObjName
        };
        this.$http.getApiFunc(this.$http.getApiStatus)(this.ListDataURL, queryData)
          .then(res => {
            if (!res.error_no) {
              this.tableData = res.data.results;
              this.dataCount = res.data.count;
            }
          })
          .catch(err => {
            console.log(err);
          })
      },
    },

    watch: {
      'pageSize': function (value) {
        this.objList();
      },
      'currentPage': function (value) {
        this.objList();
      }
    },

    computed: {
      getChoices() {
        return this.$store.state.choicesInfo
      }
    },
  }
</script>

<style scoped>
  .my-template{
    background-color: #FFFFFF;
    padding: 20px;
  }
  .my-l-butt{
    margin: 0 0 10px;
    float: left;
  }
  .my-r-float{
    float: right;
  }
  .my-put{
    width:100%;
  }
  .my-succes{
    color: #13ce66
  }
  .my-failure{
    color: red;
  }
  .my-no-in{
    color: sandybrown;
  }
  .paging {
    padding-top: 20px;
  }

  .mytable {
    /*width: 120px;*/
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

</style>
